package com.cruzr.opengles.light;

import android.content.Context;
import android.opengl.GLSurfaceView;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.view.SurfaceHolder;


public class GLView extends GLSurfaceView implements SurfaceHolder.Callback {

    private final static String TAG = "LightGLView";

    private GLRender mRender;

    public GLView(Context context) {
        super(context);
        init(context);
    }

    public GLView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context);
    }

    public void init(Context context) {
        setEGLContextClientVersion(2);
        setZOrderOnTop(true);
        setZOrderMediaOverlay(true);

        mRender = new GLRender(context);
        setRenderer(mRender);
//        setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
        setRenderMode(GLSurfaceView.RENDERMODE_CONTINUOUSLY);
    }


    @Override
    public boolean onTouchEvent(MotionEvent event) {
        int eventAction = event.getAction();
        Log.i(TAG, "onTouchEvent -> eventAction : " + eventAction);
        switch (eventAction) {
            case MotionEvent.ACTION_DOWN:
                break;

            case MotionEvent.ACTION_MOVE:

                break;

            case MotionEvent.ACTION_UP:
                mRender.setLight(event.getX(), event.getY());
                break;

            case MotionEvent.ACTION_POINTER_DOWN | 0x0100:
                break;

            default:
                break;
        }

        requestRender();
        return true;
    }
}
